package com.mo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author 墨渐生微
 * @program mo-all
 * @apiNote
 * @since 2023/1/30
 */
@RestController
@RequestMapping("/jdbc")
public class JdbcController {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @PostMapping("/query")
    public List<Map<String, Object>> query(String sql) {

        // sqlite: SELECT * FROM sqlite_master;
        return jdbcTemplate.queryForList(sql);
    }

    @PostMapping("/update")
    public int update(String sql) {
        return jdbcTemplate.update(sql);
    }
}
